package horncomb.bpm.process.instance;

import org.springframework.util.Assert;

import horncomb.bpm.process.core.ExecutionContext;
import horncomb.bpm.process.core.Token;
import horncomb.bpm.process.core.Transition;
import horncomb.bpm.task.core.TaskInstance;

/**
 * @author Daniel
 */
public class DefaultExcutionContext implements ExecutionContext {
	private TaskInstance taskInstance;
	private Token token;
	private Transition nextTransition;
	private Object contextModel;

	public DefaultExcutionContext(TaskInstance taskInstance, Object contextModel) {
		Assert.notNull(taskInstance);
		this.taskInstance = taskInstance;
		if (taskInstance.getToken() != null) {
			this.token = taskInstance.getToken();
		}
		if (contextModel != null) {
			this.contextModel = contextModel;
		} else {
			this.contextModel = new Object();
		}
	}

	public DefaultExcutionContext(Token token,
			Object contextModel) {
		Assert.notNull(token);
		this.token = token;
		if (contextModel != null) {
			this.contextModel = contextModel;
		} else {
			this.contextModel = new Object();
		}
	}

	/**
	 * {@inheritDoc}
	 */
	public Object getContextModel() {
		return contextModel;
	}

	/**
	 * {@inheritDoc}
	 */
	public void setContextModel(Object contextModel) {
		this.contextModel = contextModel;
	}

	/**
	 * {@inheritDoc}
	 */
	public Token getToken() {
		return token;
	}

	/**
	 * {@inheritDoc}
	 */
	public Transition getTransition() {
		return nextTransition;
	}

	/**
	 * {@inheritDoc}
	 */
	public void setTransition(Transition nextTransition) {
		this.nextTransition = nextTransition;
	}

	/**
	 * @return the taskInstance
	 */
	public TaskInstance getTaskInstance() {
		return taskInstance;
	}
}
